package com.guigu.youxuan.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.youxuan.pojo.SupplierInfo;
import com.guigu.youxuan.common.utils.PageUtils;
import com.guigu.youxuan.pojo.SupplierProduct;
import com.guigu.youxuan.pojo.dto.SupplierGoodsDto;
import com.guigu.youxuan.service.ISupplierProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/supplierProduct")
public class SupplierProductController {
    @Autowired
    private ISupplierProductService iSupplierProductService;
    /**
     * 分页查询供应商商品信息 商品维护
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping("/SupplierProductListPage/{sysUsersId}/{currentPage}/{pageSize}")
    @ResponseBody
    public PageInfo<SupplierProduct> SupplierProductListPage(@PathVariable int sysUsersId,
                                                             @PathVariable int currentPage,
                                                             @PathVariable int pageSize
    ){
        PageInfo<SupplierProduct> page=this.iSupplierProductService.SupplierProductListPage(sysUsersId,currentPage,pageSize);
        return page;
    }

    /**
     * 根据仓库表id查询对应的仓库信息 删除
     * @param id
     * @return
     */
    @RequestMapping("/SupplierDelById/{id}")
    @ResponseBody
    public String SupplierDelById(@PathVariable int id){
        boolean warehouse=this.iSupplierProductService.removeById(id);
        if (warehouse){
            return "ok";
        }
        return "error";
    }
    /**
     * 供应商供应把数据添加进供应商商品表
     * @param supplierProduct
     * @return
     */
    @RequestMapping("/supplierProductByIdAdd")
    @ResponseBody
    public String supplierProductByIdAdd(@RequestBody SupplierProduct supplierProduct){
        //添加
        boolean flag =this.iSupplierProductService.save(supplierProduct);
        if (flag){
            return "ok";
        }
        return "error";
    }
    /**
     * 供应商维护根据id查询数据
     * @param id
     * @return
     */
    @RequestMapping("/SupplierupdById/{id}")
    @ResponseBody
    public SupplierProduct SupplierupdById(@PathVariable int id){
        SupplierProduct goodsInfo=this.iSupplierProductService.getByIdList(id);
        return goodsInfo;
    }
    /**
     * 供应商维护修改
     * @param supplierProduct
     * @return
     */
    @RequestMapping("/SupplierupdByIdList")
    @ResponseBody
    public String SupplierupdByIdList(@RequestBody SupplierProduct supplierProduct) {
        SupplierProduct byId = iSupplierProductService.getById(supplierProduct.getId());
        byId.setPrice(supplierProduct.getPrice());
        byId.setUnit(supplierProduct.getUnit());
        boolean flag = iSupplierProductService.updateById(byId);
        if (flag) {
            return "ok";
        }
        return "error";
    }

    /**
     * 查看供应商
     * @param supplierInfo
     * @param goodsId
     * @return
     */
    @RequestMapping("/querySupplier/{goodsId}/{currentPage}/{pageSize}")
    @ResponseBody
    public PageUtils<SupplierGoodsDto> querySupplier(@RequestBody SupplierInfo supplierInfo,
                                                     @PathVariable Long goodsId,
                                                     @PathVariable int currentPage,
                                                     @PathVariable int pageSize) {
        PageUtils<SupplierGoodsDto> page = iSupplierProductService.querySupplier(supplierInfo,goodsId,currentPage,pageSize);
        return page;
    }
}
